package com.wwl.ailangchain4j.controller;

import com.wwl.ailangchain4j.assistant.Assistant;
import com.wwl.ailangchain4j.assistant.SeparateChatAssistant;
import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.service.AiServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wwl
 * 日期  2025/10/20 15:53
 * 版本 1.0
 * 描述 :
 */
@RestController
public class AssistantController {
    @Autowired
    private QwenChatModel qwenChatModel;
    @Autowired
    private Assistant assistant;
    @Autowired
    private SeparateChatAssistant separateChatAssistant;

    @GetMapping("/assistant/chat")
    public String chat(@RequestParam(value = "question", defaultValue = "你好") String question) {
        //创建chatMemory
        MessageWindowChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);
        Assistant assistant2 = AiServices.
                builder(Assistant.class)
                .chatModel(qwenChatModel)
                .chatMemoryProvider(memoryId -> chatMemory)
                .build();
        return assistant2.chat(question);
    }

    @GetMapping("/assistant/chat2")
    public String chat2(@RequestParam(value = "question", defaultValue = "你好") String question) {
        return assistant.chat(question);
    }
    @GetMapping("/assistant/testChatMemory")
    public void testChatMemory5() {
//        String answer1 = separateChatAssistant.chat(1,"我是环环");
//        System.out.println(answer1);
//        String answer2 = separateChatAssistant.chat(1,"我是谁");
//        System.out.println(answer2);
//        String answer3 = separateChatAssistant.chat(2,"我是谁");
//        System.out.println(answer3);
        String answer3 = separateChatAssistant.chat(2,"今天几号!");
        System.out.println(answer3);
    }
}
